const path = require('path');
const { ProgressPlugin } = require('webpack');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
  entry: {
    index: './src/index.js'
  },
  devtool: 'source-map', // 不配置的话，默认是 eval 处理的，对热更新友好
  output: {
    path: path.resolve(__dirname, './dist'), // 一定是绝对路径
    filename: '[name].[contenthash:8].js'
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [
          'style-loader',
          'css-loader'
        ]
      }
    ]
  },
  plugins: [
    new ProgressPlugin(),
    new CleanWebpackPlugin(), // webpack版本在5.x之后，使用clean-webpack-plugin则需要在output中配置path才可以清除成功
    new HtmlWebpackPlugin({
      template: './public/index.html',
      title: "webpack"
    }),
  ]
};